#include <bits/stdc++.h>
using namespace std;
const char str[] = "harbin";
bool s[6][256];
bool vis[256];
bool ans = false;
void dfs(int depth) {
  if (depth == 6) {
    ans = true;
    return;
  }
  for (int i = 0; i < 6; ++i) {
    if (s[depth][str[i]] && !vis[str[i]]) {
      vis[str[i]] = true;
      dfs(depth + 1);
      vis[str[i]] = false;
    }
  }
}
int main() {
  int tc;
  cin >> tc;
  cin.get();
  string buf;
  while (tc--) {
    ans = false;
    memset(s, 0, sizeof s);
    for (int i = 0; i < 6; ++i) {
      getline(cin, buf);
      for (char c : buf) {
        s[i][c] = true;
      }
    }
    for (int i = 0; i < 6; ++i) {
      if (s[0][str[i]]) {
        vis[str[i]] = true;
        dfs(1);
        vis[str[i]] = false;
      }
    }
    cout << (ans ? "Yes" : "No") << endl;
  }
}
